﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace WebUI.BL.Helper
{
    public class EncryptionManager
    {
        private byte[] Key = { 24, 83, 45, 236, 140, 228, 183, 79, 209, 234, 231, 131, 28, 7, 110, 73, 142, 236, 118, 52, 222, 46, 231, 108 };
        private byte[] IV = { 161, 205, 187, 207, 13, 92, 119, 12 };

        public string Encrypt(string inputString)
        {
            byte[] buffer = Encoding.ASCII.GetBytes(inputString);

            TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider()
            {
                Key = Key,
                IV = IV
            };
            ICryptoTransform ITransform = tripleDes.CreateEncryptor();
            return Convert.ToBase64String(ITransform.TransformFinalBlock(buffer, 0, buffer.Length));
        }
        public string Decrypt(string inputString)
        {
            byte[] buffer = Convert.FromBase64String(inputString);
            TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider()
            {
                Key = Key,
                IV = IV
            };
            ICryptoTransform ITransform = tripleDes.CreateDecryptor();
            return Encoding.ASCII.GetString(ITransform.TransformFinalBlock(buffer, 0, buffer.Length));
        }
    }
}

